//
//  HEDiesaseDetailsViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/23.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEDiesaseDetailsViewController.h"
#import "HEDieaseItemCell.h"
#import "HESpeechManager.h"

@interface HEDiesaseDetailsViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) GDTableView *tableView;
@property (nonatomic, strong) NSMutableArray *sections;
@property (nonatomic, strong) GDFormModel *formModel;

@end

@implementation HEDiesaseDetailsViewController

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [[HESpeechManager sharedManager] stopSpeech];
}
 
- (GDFormModel *)formModel {
    if (!_formModel) {
        _formModel = [[GDFormModel alloc] init];
        _formModel.proxyVC = self;
    }
    return _formModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"疾病详请";
 
    [self.view addSubview:self.tableView];
    [self initCell];
}

- (GDTableView *)tableView {
    if (!_tableView) {
        _tableView = [[GDTableView alloc] initWithFrame:CGRectMake(0, ZXNavBarHeight , KScreenWidth, KScreenHeight - ZXNavBarHeight) style:UITableViewStylePlain];
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorColor = CSplitLineColor;
        _tableView.scrollsToTop = YES;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.01)];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 0.01)];

        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = CViewBgColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        [_tableView registerClass:HEDieaseItemCell.class forCellReuseIdentifier:KHEDieaseItemCell];
    }
    return _tableView;
}

- (void)initCell {
    
    _sections = @[].mutableCopy;

    NSMutableArray *classArr = [NSMutableArray array];
    
    NSArray *titles = @[@"疾病名称：", @"相关科室：", @"患病部位：", @"相关症状：", @"小贴士："];
    
    self.formModel.ai_content = @[IsNotNull(_model.disease_name), IsNotNull(_model.disease_ks), IsNotNull(_model.disease_part), IsNotNull(_model.disease_sym), IsNotNull(_model.msg)];
    
    // 商品
    GDFiterCellModel *textModel = [GDFiterCellModel new];
    textModel.cellKlass = HEDieaseItemCell.class;
    textModel.leftTitle = @"";
    
    NSString *content = @"";
    int i = 0;
    for (NSString *str in titles) {
        GDFiterCellModel *model = [GDFiterCellModel new];
        model.cellKlass = HEDieaseItemCell.class;
        model.leftTitle = str;
        [_sections addObject:model];
        
        content = [NSString stringWithFormat:@"%@,%@,%@,",content, str, self.formModel.ai_content[i]];
        i++;
    }
    
    // 设置导航栏按钮
    [self zx_setRightBtnWithImgName:@"start_voice" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
        if ([HESpeechManager sharedManager].canSpeaker) {
            [[HESpeechManager sharedManager] startWithText:content];
        }
    }];

    [self.tableView reloadData];
}

- (void)loadData {
    [WOAFNetWorkingHandle POSTWithBaseUrl:KServerUrl suffixUrl:Kservice_all_ask parameters: @{} success:^(id  _Nonnull responseObject) {

        HEArrayResponse *response = [HEArrayResponse mj_objectWithKeyValues:responseObject];
//        [self.personConsArr addObjectsFromArray:[HEAIConsultModel mj_objectArrayWithKeyValuesArray: response.data]];
//       
//        [self.collectionView reloadData];
        
    } failure:^(NSError * _Nonnull error) {
        
    }];
}
  
#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _sections.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GDFiterCellModel *fiterModel = _sections[indexPath.row];
    HEDieaseItemCell *cell = [_tableView dequeueReusableCellWithIdentifier:KHEDieaseItemCell];
    fiterModel.fiterCellModelBlock((MCTableBaseCell *)cell, fiterModel, self.formModel, indexPath);
     return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    GDFiterCellModel *fiterModel = _sections[indexPath.row];
 
    return [tableView fd_heightForCellWithIdentifier: NSStringFromClass(fiterModel.cellKlass) cacheByIndexPath:indexPath configuration:^(MCTableBaseCell *cell) {
        [cell refreshContent:fiterModel formModel:self.formModel indexPath:indexPath];
     }];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
 
}
 

@end
